import { UserFormItemEntity } from "@/api/project/form";
import { i18n } from "@/i18n";

export type RelationType = "AND" | "OR";

export type LogicType = "show" | "jump" | "finish" | "showOption" | "checkOption";

export interface FormItemOptions {
  field: UserFormItemEntity;
}

export interface Condition {
  formItemId: string | null;
  expression: string | null;
  optionValue: any;
  relation: RelationType;
}

export interface Trigger {
  formItemId: string | null;
  type: LogicType;
  optionValue?: any;
}

export interface LogicItem {
  id: number;
  triggerList: Trigger[];
  conditionList: Condition[];
}

export interface ChangeSelect {
  type: "condition" | "trigger" | "expression";
  obj: Condition | Trigger;
}

export const SUPPORT_LOGIC_COMPONENTS = [
  "RADIO",
  "CHECKBOX",
  "CASCADER",
  "MULTIPLE_SELECT",
  "SELECT",
  "IMAGE_SELECT",
  "RATE",
  "INPUT",
  "NPS",
  "NUMBER"
] as const;

// 题目类型拥有的比较类型
export const FORM_ITEM_COMPARE_TYPE = [
  {
    value: "eq",
    label: i18n.global.t("form.logic.eq"),
    types: ["RADIO", "MULTIPLE_SELECT", "CHECKBOX", "SELECT", "IMAGE_SELECT", "RATE", "INPUT", "NPS", "NUMBER", "CASCADER"]
  },
  {
    value: "ne",
    label: i18n.global.t("form.logic.ne"),
    types: ["RADIO", "MULTIPLE_SELECT", "CHECKBOX", "SELECT", "IMAGE_SELECT", "RATE", "INPUT", "NPS", "NUMBER", "CASCADER"]
  },
  {
    value: "gt",
    label: i18n.global.t("form.logic.gt"),
    types: ["RATE", "NPS", "NUMBER"]
  },
  {
    value: "ge",
    label: i18n.global.t("form.logic.ge"),
    types: ["RATE", "NPS", "NUMBER"]
  },
  {
    value: "lt",
    label: i18n.global.t("form.logic.lt"),
    types: ["RATE", "NPS", "NUMBER"]
  },
  {
    value: "le",
    label: i18n.global.t("form.logic.le"),
    types: ["RATE", "NPS", "NUMBER"]
  },
  {
    value: "isNull",
    label: i18n.global.t("form.logic.null"),
    types: ["RADIO", "CHECKBOX", "SELECT", "MULTIPLE_SELECT", "IMAGE_SELECT", "RATE", "INPUT", "NPS", "NUMBER"]
  },
  {
    value: "notNull",
    label: i18n.global.t("form.logic.notnull"),
    types: ["RADIO", "CHECKBOX", "SELECT", "MULTIPLE_SELECT", "IMAGE_SELECT", "RATE", "INPUT", "NPS", "NUMBER"]
  },
  {
    value: "like",
    label: i18n.global.t("form.logic.like"),
    types: ["CHECKBOX", "MULTIPLE_SELECT", "INPUT"]
  },
  {
    value: "notLike",
    label: i18n.global.t("form.logic.notlike"),
    types: ["CHECKBOX", "MULTIPLE_SELECT", "INPUT"]
  }
];

export const DEFAULT_LOGIC_ITEM: Omit<LogicItem, "id"> = {
  triggerList: [
    {
      formItemId: null,
      type: "show"
    }
  ],
  conditionList: [
    {
      formItemId: null,
      expression: null,
      optionValue: null,
      relation: "AND"
    }
  ]
};
